﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using CommonExtensions.ObjectExtensions;
using CommonExtensions.StringExtensions;
using StructureMap;

namespace DBMigrator.Core.DbObjects.Data.Where
{
    public class Where : IWhere
    {
        public IWhereExpression Expression { get; private set; }    

        public IWhereCondition Column<T>(string name, Func<IWhereColumn<T>, IWhereCondition> condition)
        {
            if(name.IsBlank())
                throw new ArgumentNullException("name");
            if(condition.IsNull())
                throw new ArgumentNullException("condition");

            var column = ObjectFactory.With<string>(name).GetInstance<IWhereColumn<T>>();
            Expression = column;
            return condition(column);
        }

        public IWhereCondition Group(Func<IWhere, IWhereCondition> where)
        {
            if(where.IsNull())
                throw new ArgumentNullException("where");

            var group = ObjectFactory.GetInstance<IWhereGroup>();
            Expression = group;
            return where(group.Where);
        }
    }
}
